/*
 * @Author: lcy
 * @Date: 2023-07-03 21:14:59
 * @Last Modified by: lcy
 * @Last Modified time: 2023-07-03 21:25:22
 */

import { API_USER_CONFIG } from '@/config/api/mine'
import { request } from '@/utils/request'
interface MineSeriviceInterface {
  getUserIdByToken(params: { token: string }): Promise<any>
  getUserInfoById(params: { uid: string }): Promise<any>
}
export const useUserSerivice = (): MineSeriviceInterface => {
  class MineService {
    public async getUserIdByToken(params: { token: string }) {
      const url = API_USER_CONFIG.getUserIdByToken()
      return request
        .get(url, {
          params
        })
        .then(({ data }) => {
          return Promise.resolve(data)
        })
        .catch((err: any) => {
          return Promise.reject(err)
        })
    }
    // 根据uid获得用户信息
    public async getUserInfoById(params: { uid: string }) {
      const url = API_USER_CONFIG.getUserInfoById()
      return request
        .get(url, { params })
        .then(({ data }) => {
          return Promise.resolve(data)
        })
        .catch(err => {
          return Promise.reject(err)
        })
    }
  }
  return new MineService()
}
